#include <stdio.h>
#include <string>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

typedef struct _ROI
{
    int y1;
    int y2;
    int x1;
    int x2;
} ROI;

typedef struct _Image
{
    uint8_t *data;
    int height;
    int width;
} Image;

// 计算图像质心坐标
bool calCentroid(Image image, ROI roi, int *cx, int *cy)
{
    long long m00 = 0, m10 = 0, m01 = 0;

    for (int y = roi.y1; y < roi.y2; y++)
    {
        for (int x = roi.x1; x < roi.x2; x++)
        {
            uchar tmp = image.data[x + image.width * y];
            m00 += tmp;
            m10 += tmp * x;
            m01 += tmp * y;
        }
    }

    if (m00 != 0)
    {
        *cx = m10 / m00;
        *cy = m01 / m00;
        // cout <<"x:"<<*x<< endl;
        // cout << "y:" << *y << endl;
    }
    else
    {
        *cx = 0;
        *cy = 0;

        return false;
    }
    return true;
}

void threshold(Image src, Image dst, ROI roi, int val, int invert)
{
    int b = 255;
    int d = 0;
    if (invert)
    {
        b = 0;
        d = 255;
    }
    for (int y = roi.y1; y < roi.y2; y++)
    {
        for (int x = roi.x1; x < roi.x2; x++)
        {
            if (src.data[x + src.width * y] > val)
                dst.data[x + dst.width * y] = b;
            else
                dst.data[x + dst.width * y] = d;
        }
    }
}

void drawCross(Image img, int cx, int cy, int n)
{

    for (int i = -n; i <= n; i++)
    {
        img.data[cy * img.width + cx + i] = 255;
        img.data[(cy - i) * img.width + cx] = 255;
    }
}

void process(uint8_t *p_data, int width, int height)
{
    printf("124\r\n");
}